module.exports = function(Mogo) {
  Mogo.upload = function(file, cb) {
    let param = new FormData(); // 创建form对象
    param.append("file", file, file.name); // 通过append向form对象添加数据
    if (!global.Mogo.upload_url) throw "init 中没有设置 upload_url";
    const option = {
      url: global.Mogo.upload_url,
      method: "post",
      data: param,
      headers: { "Content-Type": "multipart/form-data" },
      onUploadProgress: function(progressEvent) {
        cb({
          progress: Number.parseInt(
            progressEvent.loaded / progressEvent.total * 100
          ),
          total: progressEvent.total,
          loaded: progressEvent.loaded
        });
      }
    };
    return Mogo.request(option);
  };
};
